package com.flyme.module.base.provider.controller;

import com.flyme.common.core.model.ResultBody;
import com.flyme.common.core.model.query.CriteriaQuery;
import com.flyme.common.core.model.query.PagerInfo;
import com.flyme.common.core.model.query.PqGrid;
import com.flyme.core.base.supper.controller.BaseController;
import com.flyme.core.base.supper.entity.EntityMap;
import com.flyme.module.base.client.api.SysInvoiceRemoteService;
import com.flyme.module.base.client.entity.SysInvoice;
import com.flyme.module.base.provider.service.SysInvoiceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author flyme
 */
@Api(tags = "发票管理")
@RestController
public class SysInvoiceController extends BaseController<SysInvoiceService, SysInvoice> implements SysInvoiceRemoteService {

    /**
     * 发票信息
     */
    @ApiOperation(value = "查询定案发票")
    @Override
    public ResultBody invoiceList(@PathVariable String id) {
        CriteriaQuery cq = new CriteriaQuery<EntityMap>(new PagerInfo());
        cq.select("invoiceTitle,invoiceType,invoiceBody,invoiceAmount,einvoice,telephone,id,email,invoiceStatus," +
            "creditCode,address,consignee,bankName,bankNo,createTime,invoiceKind,expressCompany,expressNo");
        cq.eq("orderId", id);
        PqGrid pqGrid = bizService.pageList(cq);
        return ResultBody.success(pqGrid.getRows());
    }


    @ApiOperation(value = "更新发票", notes = "更新发票")
    @Override
    public ResultBody update(@ModelAttribute SysInvoice invoice) {
        Boolean tag = bizService.saveOrUpdate(invoice);
        return ResultBody.success("更新成功").setData(tag);
    }
}
